package com.ty.day4;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/11/27 16:41
 */
public class ListDemo02 {
    public static void main(String[] args) {
        ArrayList<People> arrayList = new ArrayList<>();
        arrayList.add(new People("001","居居波",176.,60.));
        arrayList.add(new People("002","吉儿阳",170.,80.));
        arrayList.add(new People("003","唐小宇",176.,71.));
        arrayList.add(new People("004","土豆丝",150.,40.));
        arrayList.add(new People("005","冲击波",176.,50.));
        Collections.sort(arrayList);
        System.out.println(arrayList);
    }
}

class People implements Comparable<People> {
    String id;
    String name;
    Double high;
    Double weight;

    public People() {
    }

    public People(String id, String name, Double high, Double weight) {
        this.id = id;
        this.name = name;
        this.high = high;
        this.weight = weight;
    }

    @Override
    public int compareTo(People people) {
        return (int) (this.weight/Math.pow(this.high/100,2)-people.weight/Math.pow(people.high/100,2));
    }

    @Override
    public String toString() {
        return "People{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", high=" + high +
                ", weight=" + weight +
                '}';
    }
}
